<h1>New Message</h1>
	<p>
	<?php
		//ATTENTION! This path has to be relative to the path of file that is including new_message_form.php and not to the location of new_message_form itself
		include("scripts/contacts_dropdown.php");
	?>
</p>
	<p>
		<label for="title" style="font-weight:bold;">Subject</label><br />
		<input type="text" name="title" id="title" style="width:550px;" /><br />
		<div id="txtHint" ></div>
	</p>
	<p>
		<label for="text" style="font-weight:bold;">The text message</label><br />
		<textarea id="text" name="text" rows="20" cols="80" style="width: 550px; height: 100px; border: 1px solid #000000; padding: 5px; font-family: Arial, sans-serif;"></textarea><br />
		<div id="txtHint2" ></div>
	</p>
	<p>
		<input type="submit" name="send" value="Send" onclick="getemail(document.getElementById('title').value, document.getElementById('text').value, document.getElementById('option').value);"/>
		<div id="txtHint3" ></div>
	</p>
	<script type="text/javascript">
	var subject;
	var text;
	var email;
	var name;
	function getemail(str, str2, persID)
	{
		subject = str;
		text = str2;
		
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			var answer = xmlhttp.responseText;
			var splitedanswer = new Array();
			splitedanswer = answer.split(";");
			email = splitedanswer[0];
			name = splitedanswer[1];
			}
		  }
		xmlhttp.open("POST","scripts/mail/getemail.php",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("persID="+persID);
		
		sendmail();
	}
	function sendmail()
	{
	if (subject=="" || subject==" ")
	  {
	  document.getElementById("txtHint").innerHTML="<p>Please enter a subject</p>";
	  return;
	  }
	if (text=="" || text==" ")
	  {
	  document.getElementById("txtHint2").innerHTML="<p>Please enter a text</p>";
	  return;
	  }   
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==1 || xmlhttp.readyState==2 || xmlhttp.readyState==3)
		{
		document.getElementById("txtHint3").innerHTML="sending, please wait...";
		}
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("txtHint3").innerHTML=xmlhttp.responseText;
		}
	  }
	xmlhttp.open("POST","scripts/mail/email.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("subject="+subject+"&text="+text+"&email="+email+"&name="+name);
	}
	</script>
